/**
 * 
 */
package com.manthano.util.context;

import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

/**
 * @author DELL
 */
public class Context
{
	private static Logger					logger			= Logger.getLogger(Context.class);
	private static final Set<BeanFactory>	beanFactories	= new LinkedHashSet<BeanFactory>();

	/**
	 * @param beanFactory
	 */
	public static void addBeanFactory(BeanFactory beanFactory)
	{
		beanFactories.add(beanFactory);
	}

	/**
	 * @param name
	 * @return Object
	 */
	public static Object getBean(String name)
	{
		Object bean = null;
		for (BeanFactory beanFactory : beanFactories)
		{
			try
			{
				bean = beanFactory.getBean(name);
				break;
			}
			catch (NoSuchBeanDefinitionException e)
			{
				logger.error("Spring Bean not initialized = " + name, e);
			}
		}
		return bean;
	}
}
